package com.neusoft.dibuy.m3elm.jd;

import java.util.Calendar;

/**
 * TODO 简单工程设计模式
 */
public class DiscountFacltory {
    public  static  IDiscount buildDiscount()
    {
        IDiscount discount =null;
        String key = null;
        String currentKey ="xyz";
        Calendar calendar = Calendar.getInstance();
        if (  calendar.get(Calendar.DATE) ==1 &&  calendar.get(Calendar.MONTH) == 4  ){
            key ="discount51";
        } else if (  calendar.get(Calendar.DATE) ==1 &&  calendar.get(Calendar.MONTH) == 5  ){
            key ="discount61";
        }
        else if (  calendar.get(Calendar.DATE) ==1 &&  calendar.get(Calendar.MONTH) == 7  ){
            key ="discount81";
        }
        else if (  calendar.get(Calendar.DATE) ==1 &&  calendar.get(Calendar.MONTH) == 8  ){
            key ="discount91";
        }
        else discount =new IDiscount() {
            @Override
            public float count(float price) {
                return IDiscount.super.count(price);
            }
        };
//        key
        if (key.equals(currentKey)){
            return discount;
        }
        String className ="com.neusoft.dibuy.m3elm.jd.Discount51";
        try {
            discount = (IDiscount) Class.forName(className).newInstance();
            currentKey = key;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return    discount;
    }
}
